<?php

namespace AuthEntity\Model;

use Zend\Db\Adapter\Adapter;
use Zend\Db\Sql\Sql;

use Zend\Stdlib\Hydrator\ClassMethods;

class UsersEntityMapper
{
    protected $dbAdapter;
    protected $dbTable = 'users';
    protected $sql;
    public function __construct(Adapter $dbAdapter) {
        $this->dbAdapter = $dbAdapter;
        $this->sql = new Sql($dbAdapter);
        $this->sql->setTable($this->dbTable);
    }
        
    public function saveUser(UsersEntity $user)
    {
        $hydrator = new ClassMethods();
        $data = $hydrator->extract($user);        
        if($user->getUsrId())
        {
            
        }
        else
        {
            $action = $this->sql->insert();
            unset($data['usr_id']);
            $action->values($data);
        }
        $statement = $this->sql->prepareStatementForSqlObject($action);
        $result = $statement->execute();        
        return $result;
    }
    
}
